﻿
public class PostService
{
    private readonly AppDbContext _db;
    public PostService(AppDbContext db) => _db = db;

    public List<Post> GetAllPosts() => _db.Posts.ToList();
    public Post GetPost(int id) => _db.Posts.FirstOrDefault(p => p.Id == id);

    public void AddPost(Post post)
    {
        _db.Posts.Add(post);
        _db.SaveChanges();
    }
}